﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Crank.Core
{
    public class CalTokenizer : TokenizerBase
    {
        protected virtual void Initialize()
        {
            Recognize(@"^(\[[a-zA-Z_][0-9a-zA-Z_]*])", TokenType.Identifier);
            Recognize(@"^([a-zA-Z_][0-9a-zA-Z_]*)", TokenType.Identifier);
            Recognize(@"^([$])", TokenType.Identifier);
            Recognize(@"^([0-9]+)", TokenType.Number);
            Recognize(@"^(\()", TokenType.OpenBracket);
            Recognize(@"^(\))", TokenType.CloseBracket);
            Recognize(@"^(\{)", TokenType.OpenBrace);
            Recognize(@"^(\})", TokenType.CloseBrace);
            Recognize(@"^(\,)", TokenType.Comma);
            Recognize(@"^(<-)", TokenType.HasArrow);
            Recognize(@"^(<=|=>|<>)", TokenType.Operator);
            Recognize(@"^(<|>)", TokenType.Operator);
            Recognize(@"^([?!])", TokenType.SpecifityAdapter);
            Recognize(@"^([*])", TokenType.KeyAdapter);
            Recognize(@"^[^\s]+", TokenType.Unknown);
        }

        public CalTokenizer(ILineProvider source)
        {
            Initialize();
            this.source = source;
            LoadNextToken();
        }
    }
}
